import time
from celery import Celery

# 指定使用redis
# 消息中间件
broker = 'redis://127.0.0.1:6379'
# 结果存储
backend = 'redis://127.0.0.1:6379/0'

# 1.创建一个Celery对象
app = Celery('my_task', broker = broker, backend = backend)

# 2.启动Celery Worker


# 3.应用程序调用异步程序
@app.task
def add(x,y):
    # 模拟耗时操作
    time.sleep(5)
    return x+y
